home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / CheckboxGroup.java < prev    next >
Text File  |  1998-09-22  |  4KB  |  135 lines

  1. /*
  2.  * @(#)CheckboxGroup.java    1.21 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. /**
  17.  * The <code>CheckboxGroup</code> class is used to group together 
  18.  * a set of <code>Checkbox</code> buttons. 
  19.  * <p>
  20.  * Exactly one check box button in a <code>CheckboxGroup</code> can 
  21.  * be in the "on" state at any given time. Pushing any 
  22.  * button sets its state to "on" and forces any other button that 
  23.  * is in the "on" state into the "off" state. 
  24.  * <p>
  25.  * The following code example produces a new check box group,
  26.  * with three check boxes: 
  27.  * <p>
  28.  * <hr><blockquote><pre>
  29.  * setLayout(new GridLayout(3, 1));
  30.  * CheckboxGroup cbg = new CheckboxGroup();
  31.  * add(new Checkbox("one", cbg, true));
  32.  * add(new Checkbox("two", cbg, false));
  33.  * add(new Checkbox("three", cbg, false));
  34.  * </pre></blockquote><hr>
  35.  * <p>
  36.  * This image depicts the check box group created by this example:
  37.  * <p>
  38.  * <img src="images-awt/CheckboxGroup-1.gif"
  39.  * ALIGN=center HSPACE=10 VSPACE=7> 
  40.  * <p>
  41.  * @version     1.21 07/01/98
  42.  * @author     Sami Shaio
  43.  * @see         java.awt.Checkbox
  44.  * @since       JDK1.0
  45.  */
  46. public class CheckboxGroup implements java.io.Serializable {
  47.     /**
  48.      * The current choice.
  49.      */
  50.     Checkbox selectedCheckbox = null;
  51.  
  52.     /*
  53.      * JDK 1.1 serialVersionUID 
  54.      */
  55.     private static final long serialVersionUID = 3729780091441768983L;
  56.  
  57.     /**
  58.      * Creates a new instance of <code>CheckboxGroup</code>. 
  59.      * @since     JDK1.0
  60.      */
  61.     public CheckboxGroup() {
  62.     }
  63.  
  64.     /**
  65.      * Gets the current choice from this check box group.
  66.      * The current choice is the check box in this  
  67.      * group that is currently in the "on" state, 
  68.      * or <code>null</code> if all check boxes in the
  69.      * group are off.
  70.      * @return   the check box that is currently in the
  71.      *                 "on" state, or <code>null</code>.
  72.      * @see      java.awt.Checkbox
  73.      * @see      java.awt.CheckboxGroup#setSelectedCheckbox
  74.      * @since    JDK1.1
  75.      */
  76.     public Checkbox getSelectedCheckbox() {
  77.     return getCurrent();
  78.     }
  79.  
  80.     /**
  81.      * @deprecated As of JDK version 1.1,
  82.      * replaced by <code>getSelectedCheckbox()</code>.
  83.      */
  84.     public Checkbox getCurrent() {
  85.     return selectedCheckbox;
  86.     }
  87.  
  88.     /**
  89.      * Sets the currently selected check box in this group
  90.      * to be the specified check box.
  91.      * This method sets the state of that check box to "on" and 
  92.      * sets all other check boxes in the group to be off.
  93.      * <p>
  94.      * If the check box argument is <code>null</code> or belongs to a 
  95.      * different check box group, then this method does nothing. 
  96.      * @param     box   the <code>Checkbox</code> to set as the
  97.      *                      current selection.
  98.      * @see      java.awt.Checkbox
  99.      * @see      java.awt.CheckboxGroup#getSelectedCheckbox
  100.      * @since    JDK1.1
  101.      */
  102.     public void setSelectedCheckbox(Checkbox box) {
  103.         setCurrent(box);
  104.     }
  105.  
  106.     /**
  107.      * @deprecated As of JDK version 1.1,
  108.      * replaced by <code>setSelectedCheckbox(Checkbox)</code>.
  109.      */
  110.     public synchronized void setCurrent(Checkbox box) {
  111.     if (box != null && box.group != this) {
  112.         return;
  113.     }
  114.     Checkbox oldChoice = this.selectedCheckbox;
  115.     this.selectedCheckbox = box;
  116.     if ((oldChoice != null) && (oldChoice != box)) {
  117.         oldChoice.setState(false);
  118.     }
  119.     if (box != null && oldChoice != box && !box.getState()) {
  120.         box.setStateInternal(true);
  121.     }
  122.     }
  123.  
  124.     /**
  125.      * Returns a string representation of this check box group,
  126.      * including the value of its current selection.
  127.      * @return    a string representation of this check box group.
  128.      * @since     JDK1.0
  129.      */
  130.     public String toString() {
  131.     return getClass().getName() + "[selectedCheckbox=" + selectedCheckbox + "]";
  132.     }
  133.  
  134. }
  135.